package com.xy.handler;

import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.xy.constants.RabbitConstant;
import com.xy.service.IViewerService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.BeanUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@AllArgsConstructor
public class QueueBdFace {
	private final IViewerService viewerService;
	@RabbitListener(queues = RabbitConstant.TOPIC_ADD_FACE_QUEUE)
	@RabbitHandler
	public void addFace(String str, Message message, Channel channel) {
		log.info("队列1 百度人脸注册，接收消息：{}",str);
		createPersonBd();
	}
	@RabbitListener(queues = RabbitConstant.TOPIC_DELETE_FACE_QUEUE)
	@RabbitHandler
	public void updateFace(JSONObject jsonObject, Message message, Channel channel) {
		log.info("队列1 百度人脸修改 ，接收消息：{}",jsonObject);
		deletePersonBd();
	}
	@RabbitListener(queues = RabbitConstant.TOPIC_UPDATE_FACE_QUEUE)
	@RabbitHandler
	public void delFace(JSONObject jsonObject, Message message, Channel channel) {
		log.info("队列1 百度人脸修改，接收消息：{}",jsonObject);
		updatePersonBd();
	}
	public void updatePersonBd(){

//		try {
//			boolean upateFace = AipFaceClient.upateFace(queueFaceDTO.getTicketId(), queueFaceDTO.getGroupId(), queueFaceDTO.getPhotoUrl());
//		} catch (Exception e) {
//			log.info("百度人脸修改失败用户信息{}",queueFaceDTO);
//		}
	}
	public void deletePersonBd(){

//		try {
//			AipFaceClient.deleteFace(queueFaceDTO.getTicketId(),queueFaceDTO.getGroupId());
//		} catch (Exception e) {
//			log.info("百度人脸删除失败用户信息{}",queueFaceDTO);
//		}
	}
	public void createPersonBd(){

//		try {
//			boolean addFace = AipFaceClient.addFace(queueFaceDTO.getTicketId(), queueFaceDTO.getGroupId(), queueFaceDTO.getPhotoUrl());
//			if(addFace){
//				TicketEntity ticketEntity = BeanUtil.newInstance(TicketEntity.class);
//				ticketEntity.setId(Long.parseLong(queueFaceDTO.getTicketId()));
//				ticketEntity.setRegistFace(0);
//				ticketService.updateById(ticketEntity);
//			}
//		} catch (Exception e) {
//			log.info("百度人脸注册失败用户信息{}",queueFaceDTO);
//		}
	}
}
